<template>
<h1>员工列表练习</h1>
  <input type="text" v-model="employee.name" placeholder="请输入员工姓名">
  <input type="text" v-model="employee.salary" placeholder="请输入员工薪资">
  <input type="text" v-model="employee.job" placeholder="请输入员工岗位">
  <button @click="add">添加</button>
  <hr>
  <table border="1">
    <thead>
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>岗位</th>
    </tr>
    <tr v-for="(item,index) in employee_arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
    </thead>
  </table>
</template>

<script setup>

import {ref} from "vue";

const employee = ref({
  name:'',
  salary:'',
  job:''
})
const employee_arr = ref([])
const add = ()=>{
  if(employee.value.name.trim()===''||employee.value.salary.trim()===''||employee.value.job.trim()===''){
    alert('输入不能为空');
    return;
  }
  employee_arr.value.push({
    name:employee.value.name,
    salary:employee.value.salary,
    job:employee.value.job
  })
  employee.value.name='';
  employee.value.salary='';
  employee.value.job='';
}


</script>


<style scoped>

</style>